package spring.aop;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * pointcut case
 */
@Component("AppTestPointCut")
@Aspect
public class AppTestPointCut {

	@Pointcut("execution(* *Students(..))")
	public void pointcut() {
	}

	@Before(value = "pointcut()")
	public void before() {
		System.out.println("...................before");
	}

	@After(value = "pointcut()")
	public void after() {
		System.out.println("...................after");
	}

	@Around(value = "pointcut()")
	public Object around(ProceedingJoinPoint point) throws Throwable {
		long time = System.currentTimeMillis();
		Object retVal = point.proceed();
		System.out.println("方法运行时间：" + (System.currentTimeMillis() - time));
		return retVal;
	}

	@AfterThrowing(pointcut="pointcut()",throwing="ex")
	public void doThrowing( Exception ex) {
		System.out.println("throw a exception..."+ex.getMessage());
	}

}
